package com.ruoyi.industryfrontend.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.industryfrontend.domain.ProjectLand;
import com.ruoyi.industryfrontend.service.IProjectLandService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 土地Controller
 *
 * @author MagicCube
 * @date 2023-06-05
 */
@RestController
@RequestMapping("/land")
public class ProjectLandController extends BaseController
{
    @Autowired
    private IProjectLandService projectLandService;

    /**
     * 查询土地列表
     */
    @RequiresPermissions("myIndustry:land:list")
    @GetMapping("/list")
    public TableDataInfo list(ProjectLand projectLand)
    {
        startPage();
        List<ProjectLand> list = projectLandService.selectProjectLandList(projectLand);
        return getDataTable(list);
    }

    /**
     * 导出土地列表
     */
    @RequiresPermissions("myIndustry:land:export")
    @Log(title = "土地", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectLand projectLand)
    {
        List<ProjectLand> list = projectLandService.selectProjectLandList(projectLand);
        ExcelUtil<ProjectLand> util = new ExcelUtil<ProjectLand>(ProjectLand.class);
        util.exportExcel(response, list, "土地数据");
    }

    /**
     * 获取土地详细信息
     */
    @RequiresPermissions("myIndustry:land:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(projectLandService.selectProjectLandById(id));
    }

    /**
     * 新增土地
     */
    @RequiresPermissions("myIndustry:land:add")
    @Log(title = "土地", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectLand projectLand)
    {
        return toAjax(projectLandService.insertProjectLand(projectLand));
    }

    /**
     * 修改土地
     */
    @RequiresPermissions("myIndustry:land:edit")
    @Log(title = "土地", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectLand projectLand)
    {
        return toAjax(projectLandService.updateProjectLand(projectLand));
    }

    /**
     * 删除土地
     */
    @RequiresPermissions("myIndustry:land:remove")
    @Log(title = "土地", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectLandService.deleteProjectLandByIds(ids));
    }
}
